package com.wd.live.view.activity

import android.content.Intent
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.wd.live.R
import com.wd.live.databinding.ActivityHomeBinding
import com.wd.live.model.base.BaseActivity
import com.wd.live.model.base.BaseViewModel
import com.wd.live.view.fragment.BillboardFragment
import com.wd.live.view.fragment.FVicinityFragment
import com.wd.live.view.fragment.GSquareFragment
import com.wd.live.view.fragment.MyFragment
/**
 * 作者：马海钊
 * 时间：2023年8月17日14:58:12
 * 功能：首页
 */
class HomeActivity : BaseActivity<BaseViewModel, ActivityHomeBinding>() {
    private val mFragments:MutableList<Fragment> = mutableListOf(
        //广场
        GSquareFragment(),
        //附近
        FVicinityFragment(),
        //榜单
        BillboardFragment(),
        //我的
        MyFragment(),
    )
    override fun initData() {
        binding.openliveId.setOnClickListener {
            startActivity(Intent(this,DialogActivity::class.java))
        }
        binding.viewPage.apply {
            adapter = ScreenSlidePagerAdapter(supportFragmentManager, lifecycle)
            isUserInputEnabled = false
        }
        binding.viewPage.offscreenPageLimit=4
        binding.radioGroup.apply {
            check(R.id.redio_button_1)
            setOnCheckedChangeListener { group, checkedId ->
                when (checkedId) {
                    R.id.redio_button_1 ->
                        binding.viewPage.currentItem = 0

                    R.id.redio_button_2 ->
                        binding.viewPage.currentItem = 1

                    R.id.redio_button_3 ->
                        binding.viewPage.currentItem = 2

                    R.id.redio_button_4 ->
                        binding.viewPage.currentItem = 3
                }
            }
        }

    }

    private inner class ScreenSlidePagerAdapter
        (fa: FragmentManager, lc: Lifecycle) : FragmentStateAdapter(fa, lc) {
        override fun getItemCount(): Int = mFragments.size
        override fun createFragment(position: Int)=mFragments[position]
    }

    override fun getViewBinding() = ActivityHomeBinding.inflate(layoutInflater)
}